home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / VideoToolbox 94.11.17 / Utilities / TestAttenuator / TestAttenuator.c next >
Encoding:
C/C++ Source or Header  |  1994-11-04  |  4.8 KB  |  199 lines  |  [TEXT/KAHL]

  1. /*
  2. TestAttenuator.c
  3. This produced a simple test pattern that allows a quick yes/no evaluation of the
  4. attenuator before shipping. Mainly this is a check to make sure that all the
  5. resistors were soldered correctly.
  6. HISTORY:
  7. 11/89     dgp wrote it
  8. 9/9/90    dgp    make the arrays static.
  9. 10/17/90    dgp    remove unused variable
  10. 2/16/91        dgp    added check for fpu and color quickdraw
  11. 8/24/91    dgp    Made compatible with THINK C 5.0.
  12. 3/10/92    dgp    include mc68881.h
  13. 4/27/92    dgp    call SetDepth to set screen to 8 bits.
  14. 8/27/92    dgp    replace SysEnvirons() by Gestalt()
  15. 2/7/93    dgp    updated to use SetPixelsQuickly.
  16. */
  17. #include "VideoToolbox.h"
  18. #include <math.h>
  19. #include "Luminance.h"
  20. #if (THINK_C || THINK_CPLUS)
  21.     #include <console.h>
  22. #endif
  23.  
  24. #define XMAX         640        /* Maximum horizontal coordinate */ 
  25. #define YMAX         480        /* Maxumum vertical coordinate */
  26.  
  27. void TestAttenuator(void);
  28.  
  29. void main(void)
  30. {
  31.     Require(gestalt8BitQD);
  32.     TestAttenuator();
  33. }
  34.  
  35. void TestAttenuator(void)
  36. {
  37.     register short i,j,k;
  38.     double a,A,AA;
  39.     CWindowPtr window=NULL;
  40.     WindowPtr oldWindow=NULL;
  41.     GDHandle device=NULL,oldGDHandle=NULL;
  42.     static LuminanceRecord LR;
  43.     short n,mode;
  44.     static double fy[YMAX];
  45.     double c;
  46.     static unsigned long row[XMAX];
  47.     short oldScreen;
  48.     char string[100];
  49.     
  50.     /* parameters of the screen calibration */
  51.     
  52.     #if (THINK_C || THINK_CPLUS)
  53.         console_options.top=YMAX/2-40;
  54.         console_options.nrows=7;
  55.         console_options.txSize=9;
  56.     #endif
  57.     printf("Welcome to TestAttenuator.\n");
  58.     #include "LuminanceRecord1.h"                    // read at compile time
  59.     printf("%s\n",LR.notes);
  60.     oldScreen=LR.screen;
  61.     if(GetScreenDevice(1)!=NULL){
  62.         for(; ;){
  63.             printf("Which screen would you like to use for this test? (%d):",LR.screen);
  64.             gets(string);
  65.             sscanf(string,"%d",&LR.screen);
  66.             device=GetScreenDevice(LR.screen);
  67.             if(device!=NULL)break;
  68.             else printf("Sorry, there is no device %d\n",LR.screen);
  69.         }
  70.     }else LR.screen=0;
  71.     sprintf(string,"LuminanceRecord%d.h",LR.screen);
  72.     i=ReadLuminanceRecord(string,&LR,0);        // try to read latest LuminanceRecord
  73.     if(i<1)printf("Warning: couldn't find ā€œ%sā€. Calibrating screen %d.\n"
  74.         ,string,LR.screen);
  75.     else oldScreen=LR.screen;
  76.  
  77.     /* Find device corresponding to the experimental screen. */
  78.     oldGDHandle = GetGDevice();
  79.     device = GetScreenDevice(LR.screen);
  80.     if(GDClutSize(device)!=256 && NewPaletteManager()){
  81.         mode=HasDepth(device,8,1,1);
  82.         if(mode!=0)SetDepth(device,mode,1,1);        // 8-bit pixelSize, color
  83.     }
  84.     if(GDClutSize(device)!=256){
  85.         PrintfExit("Sorry, I require a screen with 256 colors.\n");
  86.     }
  87.     
  88.     GetPort(&oldWindow);
  89.     window = GDOpenWindow(device);
  90.     SetPort((WindowPtr)window);
  91.     
  92.     for(j=0;j<YMAX/2;j++){
  93.         fy[j]=cos(j*2.0*PI/80.0);
  94.     }
  95.     c=1.0;
  96.     SetLuminances(device,&LR,11,90,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  97.     c/=6.0;
  98.     SetLuminances(device,&LR,91,170,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  99.     c/=6.0;
  100.     SetLuminances(device,&LR,171,250,LR.LMin,LR.LMin+(LR.LMax-LR.LMin)*c);
  101.     /* Display a swept-contrast sinusoid */
  102.     for(j=0;j<YMAX/2;j++){
  103.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  104.         k+=11;
  105.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  106.         SetPixelsQuickly(0,j,row,1+XMAX/3);
  107.     }
  108.     c *=6.0;
  109.     for(j=0;j<YMAX/2;j++){
  110.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  111.         k+=91;
  112.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  113.         SetPixelsQuickly(XMAX/3,j,row,1+XMAX/3);
  114.     }
  115.     c *=6.0;
  116.     for(j=0;j<YMAX/2;j++){
  117.         k=floor(0.5+79.0*0.5*c*(1.0 + fy[j]));
  118.         k+=171;
  119.         for(i=0;i<1+XMAX/3;i++)row[i]=k;
  120.         SetPixelsQuickly(2*XMAX/3,j,row,1+XMAX/3);
  121.     }
  122.  
  123.     /* compute three clut entries that ought to produce equal luminances */
  124.     AA=LToV(&LR,LR.LMax/4.0);
  125.     printf("%f cd/m^2 equivalent number is %f\n",VToL(&LR,AA),AA);
  126.     i=251;
  127.     A=AA;
  128.     a=A/LR.r;
  129.     if(a>255.) n=255;
  130.     else n=a;
  131.     LR.table[i].rgb.red=n<<8;
  132.     A -= n*LR.r;
  133.     a=A/LR.g;
  134.     if(a>255.) n=255;
  135.     else n=a;
  136.     LR.table[i].rgb.green=n<<8;
  137.     A -= n*LR.g;
  138.     a=A/LR.b;
  139.     if(a>255.) n=255;
  140.     else n=a;
  141.     LR.table[i].rgb.blue=n<<8;
  142.     A -= n*LR.b;
  143.     i++;
  144.     A=AA;
  145.     a=A/LR.g;
  146.     if(a>255.) n=255;
  147.     else n=a;
  148.     LR.table[i].rgb.green=n<<8;
  149.     A -= n*LR.g;
  150.     a=A/LR.b;
  151.     if(a>255.) n=255;
  152.     else n=a;
  153.     LR.table[i].rgb.blue=n<<8;
  154.     A -= n*LR.b;
  155.     a=A/LR.r;
  156.     if(a>255.) n=255;
  157.     else n=a;
  158.     LR.table[i].rgb.red=n<<8;
  159.     A -= n*LR.r;
  160.     i++;
  161.     A=AA;
  162.     a=A/LR.b;
  163.     if(a>255.) n=255;
  164.     else n=a;
  165.     LR.table[i].rgb.blue=n<<8;
  166.     A -= n*LR.b;
  167.     a=A/LR.r;
  168.     if(a>255.) n=255;
  169.     else n=a;
  170.     LR.table[i].rgb.red=n<<8;
  171.     A -= n*LR.r;
  172.     a=A/LR.g;
  173.     if(a>255.) n=255;
  174.     else n=a;
  175.     LR.table[i].rgb.green=n<<8;
  176.     A -= n*LR.g;
  177.     i++;
  178.     for(i=251;i<254;i++) printf("%4d,%4d,%4d = %6.2f == %7.3f cd/m^2\n",
  179.         LR.table[i].rgb.red/256,LR.table[i].rgb.green/256,LR.table[i].rgb.blue/256,
  180.         LToV(&LR,GetLuminance(NULL,&LR,i)), GetLuminance(NULL,&LR,i));
  181.     LoadLuminances(device,&LR,251,253);
  182.     
  183.     /* Display stripes */
  184.     for(i=0;i<XMAX;) {
  185.         for(k=0;k<10;k++)row[i++]=251;
  186.         for(k=0;k<10;k++)row[i++]=252;
  187.         for(k=0;k<10;k++)row[i++]=253;
  188.     }
  189.     for(j=YMAX/2;j<YMAX;j++)SetPixelsQuickly(0,j,row,XMAX);
  190.     
  191.     printf("Hit return to quit.");
  192.     getchar();
  193.     SetPort(oldWindow);
  194.     SetGDevice(oldGDHandle);
  195.     GDDisposeWindow(window);
  196.     RestoreCluts();
  197.     abort();
  198. }
  199.